<?php

class User extends DataMapper {
 
 /*  var $validation = array(
        'user_login' => array(
            'label' => 'Tên truy cập',
            'rules' => array('required', 'trim', 'unique', 'min_length' => 3, 'max_length' => 20)
        ),
        'user_pass' => array(
            'label' => 'Mật khẩu',
            'rules' => array('required', 'trim', 'min_length' => 3)
        ),
        
        'user_email' => array(
            'label' => 'Địa chỉ Email ',
            'rules' => array('required', 'trim', 'valid_email')
        )
    );
    */
    
    public  $has_one = array("authitem"); 
    public function __construct()
    {
        // model constructor
        parent::__construct();
    }   
    
    /**
     * checkExistUser
     * 
     * @author hungpv@tasvis.com.vn
     * @deprecated Check if exist user in system 
     * 
     * @param String $username for Username
     * @param String $email for Email
     * @return boolean return true if exist, or return false if not.
     */
    function checkExistUser($username,$email)
    {
        $user = new User();
        $count = $user->where("user_login",$username)
                ->or_where("user_email", $email)
                ->count();
        if($count>0)
        {
            return true;
        }
        else
        {
            return false;
        }
    }
    
    function checkExistUsername($username)
    {
        $user = new User();
        $count = $user->where("user_login",$username)                
                ->count();
        if($count>0)
        {
            return true;
        }
        else
        {
            return false;
        }
    }
    
    function checkExistUserEmail($email)
    {
        $user = new User();
        $count = $user->where("user_email", $email)
                ->count();
        if($count>0)
        {
            return true;
        }
        else
        {
            return false;
        }
    }
}
?>

